package com.hd.trans.dialog

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import com.hd.trans.R
import com.hd.trans.binding.setOnDebouncedClickListener
import com.hd.trans.databinding.PopVoiceRecordMenuBinding
import com.hd.trans.db.bean.TranslateRecord
import com.hd.trans.framework.dialog.CstBindPop

class VoiceTransRecordMenuPop(context: Context): CstBindPop<PopVoiceRecordMenuBinding>(
    LayoutInflater.from(context).inflate(R.layout.pop_voice_record_menu,null)) {

    var onItemClick:((String)->Unit)? = null

    var data: TranslateRecord? = null
        set(value) {
            field = value
            mDataBinding.ivCollectIcon.setImageResource(if(data?.isCollected == true) R.mipmap.trans_collect2 else R.mipmap.trans_un_collect2)
        }

    init {
        width = ViewGroup.LayoutParams.WRAP_CONTENT
        height = ViewGroup.LayoutParams.WRAP_CONTENT

        mDataBinding.apply {
            itemCopy.setOnDebouncedClickListener {
                onItemClick?.invoke("copy")
                dismiss()
            }

            itemEdit.setOnDebouncedClickListener {
                onItemClick?.invoke("edit")
                dismiss()
            }

            itemCollect.setOnDebouncedClickListener {
                onItemClick?.invoke("collect")
                mDataBinding.ivCollectIcon.postDelayed({
                    dismiss()
                }, 200)
            }

            itemEnlarge.setOnDebouncedClickListener {
                onItemClick?.invoke("enlarge")
                dismiss()
            }

            itemShare.setOnDebouncedClickListener {
                onItemClick?.invoke("share")
                dismiss()
            }

            itemDelete.setOnDebouncedClickListener {
                onItemClick?.invoke("delete")
                dismiss()
            }


        }

    }



}